<%@ page language="java" contentType="text/html; charset=UTF-8"
	pageEncoding="UTF-8"%>

<!-- Header -->
<header data-am-widget="header"
	class="am-header am-header-default am-header-fixed">
	<div class="am-header-left am-header-nav">
		<a id="window-back" href="#" data-am-offcanvas> <i
			class="am-icon-chevron-left"></i> <span class="am-header-nav-title">登录</span>
		</a>
	</div>
	<h1 class="am-header-title"></h1>
	<div class="am-header-right am-header-nav">
		<a href="mobile/register" class=""> <span
			class="am-header-nav-title">快速注册</span>
		</a>
	</div>
</header>

<div style="height: 15px"></div>
<!-- login form -->
<div class="am-g">
	<div class="am-u-md-12 am-u-sm-centered">
		<form id="loginForm" class="am-form my-form">
			<fieldset class="am-form-set">
				<div class="am-form-group">
					<input type="text" id="mobile" placeholder="手机号"
					data-validation-message="手机格式不正确" pattern="^1((3|5|8){1}\d{1}|70)\d{8}$" required> 
				</div>
				<div class="am-form-group">
					<input id="pwd" type="password" placeholder="密码" required>
				</div>
			</fieldset>
			<button id="loginBtn" type="button" class="am-btn am-btn-success am-btn-block">登录</button>
			<a href="mobile/findPassword"
				class="am-btn am-btn-default am-btn-block">忘记密码</a>
		</form>
	</div>
</div>

<script type="text/javascript">
	$(function() {
		$('.am-form').validator({
		    onValid: function(validity) {
		      $(validity.field).closest('.am-form-group').find('.am-alert').hide();
		    },

		    onInValid: function(validity) {
		      var $field = $(validity.field);
		      var $group = $field.closest('.am-form-group');
		      var $alert = $group.find('.am-alert');
		      // 使用自定义的提示信息 或 插件内置的提示信息
		      var msg = $field.data('validationMessage') || this.getValidationMessage(validity);

		      if (!$alert.length) {
		        $alert = $('<div class="am-alert am-alert-danger"></div>').hide().
		          appendTo($group);
		      }

		      $alert.html(msg).show();
		    }
		  });
		
		$('#loginBtn').click(function(){
			if($('.am-form').data('amui.validator').isFormValid()){
				$.post('mobile/login', {
					mobile : $('#mobile').val(),
					pwd: $('#pwd').val()
				}, function(result) {
					if (result.code == 'ACK') {
						if(result.message == 'errorMsg'){
							showAlert(result.data);
						}else{
							var gotoURL = '${gotoURL}';
							if(isNotEmpty(gotoURL)){
								showSuccessMsg(result.data, gotoURL);
							}else{
								showSuccessMsg(result.data, "mobile/selection");
							}
						}
					}
				}, 'json');
			}
		});
	});
</script>